<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr"><head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>java 监控linux CPU 内存 磁盘 JVM： - chixianhuadeyu - ITeye技术网站</title>
    <meta name="description" content="import java.io.*;&nbsp;&nbsp;  &nbsp;  /**&nbsp;   * linux 下cpu 内存 磁盘 jvm的使用监控&nbsp;   * @author avery_leo&nbsp;   *&nbsp;   */&nbsp;  public class TT {&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp; /**&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; * 获取cpu使用情况&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp; */&nbsp;  &nbsp;&nbsp; ...">
    <meta name="keywords" content="JVM, Linux, Java, RedHat java 监控linux CPU 内存 磁盘 JVM：">
    <link rel="shortcut icon" href="http://chixianhuadeyu.iteye.com/images/favicon.ico" type="image/x-icon">
    <link rel="search" type="application/opensearchdescription+xml" href="http://chixianhuadeyu.iteye.com/open_search.xml" title="ITeye">
    <link href="http://chixianhuadeyu.iteye.com/rss" rel="alternate" title="chixianhuadeyu" type="application/rss+xml">
    <link href="222954_files/blog.css" media="screen" rel="stylesheet" type="text/css">
<link href="222954_files/theme.css" media="screen" rel="stylesheet" type="text/css">
    <script src="222954_files/ga.js" async="" type="text/javascript"></script><script src="222954_files/application.js" type="text/javascript"></script>
    <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-535605-1']);
  _gaq.push(['_setDomainName', 'iteye.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>


      <link href="222954_files/SyntaxHighlighter.css" media="screen" rel="stylesheet" type="text/css">
  <script src="222954_files/shCoreCommon.js" type="text/javascript"></script>
<script src="222954_files/hotkey.js" type="text/javascript"></script>
  <script src="222954_files/code_favorites.js" type="text/javascript"></script>
<script src="222954_files/weiboshare.js" type="text/javascript"></script>
  <style>
    div#main {background-color: transparent; border: 0; padding: 0px; width: 740px;}
  </style>
  </head>
  <body>
    <div id="header">
      <div id="blog_site_nav">
  <a href="http://www.iteye.com/" class="homepage">首页</a>
  <a href="http://www.iteye.com/news">资讯</a>
  <a href="http://www.iteye.com/magazines">精华</a>
  <a href="http://www.iteye.com/forums">论坛</a>
  <a href="http://www.iteye.com/ask">问答</a>
  <a href="http://www.iteye.com/blogs">博客</a>
  <a href="http://www.iteye.com/groups">群组</a>
  <a href="#" onclick="return false;" id="msna"><u>更多</u> <small>▼</small></a>
  <div class="quick_menu" style="display:none;">
    <a href="http://www.iteye.com/job">招聘</a>
    <a href="http://www.iteye.com/search">搜索</a>
  </div>
</div>
      <div id="user_nav">
      <a href="http://chixianhuadeyu.iteye.com/login" class="welcome" title="登录">您还未登录 !</a>
    <a href="http://chixianhuadeyu.iteye.com/login">登录</a>
    <a href="http://chixianhuadeyu.iteye.com/signup" class="nobg">注册</a>
  </div>

    </div>

    <div id="page">
      <div id="branding" class="clearfix">
        <div id="blog_name"><h1><a href="http://chixianhuadeyu.iteye.com/">chixianhuadeyu</a></h1></div>
        <div id="blog_preview">
          
        </div>
        <div id="blog_domain">永久域名 <a href="http://chixianhuadeyu.iteye.com/">http://chixianhuadeyu.iteye.com</a></div>
      </div>
      
      <div id="content" class="clearfix">
        <div id="main">
          


          


<div class="blog_main">
  <div class="blog_nav">
    
    <div class="pre_next">
      <a href="http://chixianhuadeyu.iteye.com/blog/222955" class="next" title="java 监控硬盘">java 监控硬盘</a>
      |
      <a href="http://chixianhuadeyu.iteye.com/blog/222952" class="pre" title="用java取得linux系统cpu、内存的实时信息">用java取得linux系统cpu、内存的实时信息</a>
    </div>
  </div>
  <div class="blog_title">
    <div class="date"><span class="year">2008</span><span class="sep_year">-</span><span class="month">08</span><span class="sep_month">-</span><span class="day">01</span></div>
    <h3>
      <a href="http://chixianhuadeyu.iteye.com/blog/222954">java 监控linux CPU 内存 磁盘 JVM：</a>
      <em class="actions">      </em>
    </h3>
    <ul class="blog_categories"><strong>博客分类：</strong> <li><a href="http://chixianhuadeyu.iteye.com/category/26631">温暖心灵</a></li> </ul>
        <div class="news_tag"><a href="http://www.iteye.com/blogs/tag/JVM">JVM</a><a href="http://www.iteye.com/blogs/tag/Linux">Linux</a><a href="http://www.iteye.com/blogs/tag/Java">Java</a><a href="http://www.iteye.com/blogs/tag/RedHat">RedHat</a></div>
  </div>

  <div id="blog_content" class="blog_content">
    import java.io.*;&nbsp;&nbsp; 
<br>&nbsp; 
<br>/**&nbsp; 
<br> * linux 下cpu 内存 磁盘 jvm的使用监控&nbsp; 
<br> * @author avery_leo&nbsp; 
<br> *&nbsp; 
<br> */&nbsp; 
<br>public class TT {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; /**&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * 获取cpu使用情况&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; */&nbsp; 
<br>&nbsp;&nbsp;&nbsp; public double getCpuUsage() throws Exception {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double cpuUsed = 0;&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Runtime rt = Runtime.getRuntime();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process p = rt.exec("top -b -n 1");// 调用系统的“top"命令&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BufferedReader in = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
in = new BufferedReader(new 
InputStreamReader(p.getInputStream()));&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String str = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String[] strArray = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ((str = in.readLine()) != null) {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int m = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if (str.indexOf(" R ") != -1) {// 只分析正在运行的进程，top进程本身除外 
&amp;&amp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 strArray = str.split(" ");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 for (String tmp : strArray) {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if (tmp.trim().length() == 0)&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 continue;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if (++m == 9) {// 第9列为CPU的使用百分比(Red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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } finally {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in.close();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return cpuUsed;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>/**&nbsp; 
<br> * 内存监控&nbsp; 
<br> * @return&nbsp; 
<br> * @throws Exception&nbsp; 
<br> */&nbsp; 
<br>&nbsp;&nbsp;&nbsp; public double getMemUsage() throws Exception {&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double menUsed = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Runtime rt = Runtime.getRuntime();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process p = rt.exec("top -b -n 1");// 调用系统的“top"命令&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BufferedReader in = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
in = new BufferedReader(new 
InputStreamReader(p.getInputStream()));&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String str = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String[] strArray = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ((str = in.readLine()) != null) {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int m = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 if (str.indexOf(" R ") != -1) {// 只分析正在运行的进程，top进程本身除外 
&amp;&amp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 //&nbsp;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 // 
System.out.println("------------------3-----------------");&nbsp;&n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nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return menUsed;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp; /**&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * 获取磁盘空间大小&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; *&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * @return&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; * @throws Exception&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp; */&nbsp; 
<br>&nbsp;&nbsp;&nbsp; public double getDeskUsage() throws Exception {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double totalHD = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; double usedHD = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Runtime rt = Runtime.getRuntime();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process p = rt.exec("df -hl");//df -hl 查看硬盘空间&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BufferedReader in = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
in = new BufferedReader(new 
InputStreamReader(p.getInputStream()));&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String str = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String[] strArray = null;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int flag = 0;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while ((str = in.readLine()) != null) {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int m = 0;&nbsp;&nbsp; 
<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (flag &gt; 0) {&nbsp;&nbsp; 
<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag++;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 strArray = str.split(" ");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 for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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 }&nbsp;&nbsp; 
<br>&nbsp; 
<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (Exception e) {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } finally {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; in.close();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (usedHD / totalHD) * 100;&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>&nbsp; 
<br>&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Exception {&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TT cpu = new TT();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("---------------cpu used:" + cpu.getCpuUsage() + 
"%");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("---------------mem used:" + cpu.getMemUsage() + 
"%");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("---------------HD used:" + cpu.getDeskUsage() + 
"%");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("------------jvm监控----------------------");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Runtime lRuntime = Runtime.getRuntime();&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("--------------Free Momery:" + 
lRuntime.freeMemory()+"K");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("--------------Max Momery:" + 
lRuntime.maxMemory()+"K");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
System.out.println("--------------Total Momery:" + 
lRuntime.totalMemory()+"K");&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("---------------Available Processors :"&nbsp; 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 + lRuntime.availableProcessors());&nbsp;&nbsp; 
<br>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 
<br>}&nbsp; 
<br>
  </div>

  


  <iframe src="222954_files/468x60v2.html" frameborder="0" height="60" scrolling="no" width="468"></iframe>
  
  <div id="bottoms" class="clearfix">
    
    <div id="share_weibo">分享到：
      <a data-type="sina" href="javascript:;" title="分享到新浪微博"><img src="222954_files/t_sina.gif"></a>
      <a data-type="qq" href="javascript:;" title="分享到腾讯微博"><img src="222954_files/t_qq.gif"></a>
    </div>
  </div>

  <div class="blog_nav">
    <div class="pre_next">
      <a href="http://chixianhuadeyu.iteye.com/blog/222955" class="next" title="java 监控硬盘">java 监控硬盘</a>
      |
      <a href="http://chixianhuadeyu.iteye.com/blog/222952" class="pre" title="用java取得linux系统cpu、内存的实时信息">用java取得linux系统cpu、内存的实时信息</a>
    </div>
  </div>
  <div class="blog_bottom">
    <ul>
      <li>21:31</li>
      <li><a href="#comments">评论</a> / 浏览 (0 / 3563)</li>
      
      
            
      <li class="last"><a href="http://www.iteye.com/wiki/blog/222954" target="_blank" class="more">相关推荐</a></li>
    </ul>
  </div>

  <div class="blog_comment">
    <h5>评论</h5>
    <a id="comments" name="comments"></a>
    
    
    
  </div>

  <div class="blog_comment">
    <h5>发表评论</h5>
            <p style="text-align:center; margin-top:30px;margin-bottom:0px;"><a href="http://chixianhuadeyu.iteye.com/login" style="background-color: white;"> <img src="222954_files/login_icon.png" style="vertical-align: middle; margin-right: 10px;"></a><a href="http://chixianhuadeyu.iteye.com/login">  您还没有登录,请您登录后再发表评论 </a></p>
      </div>
</div>


<script type="text/javascript">
  dp.SyntaxHighlighter.HighlightAll('code', true, true);

  $$('#main .blog_content pre[name=code]').each(function(pre, index){ // blog content
    var post_id = 222954;
    var location = window.location;
    source_url = location.protocol + "//" + location.host + location.pathname + location.search;
    pre.writeAttribute('codeable_id', post_id);
    pre.writeAttribute('codeable_type', "Blog");
    pre.writeAttribute('source_url', source_url);
    pre.writeAttribute('pre_index', index);
    pre.writeAttribute('title', 'java 监控linux CPU 内存 磁盘 JVM：');
  });
  $$('#main .blog_comment > div').each(function(comment){// comment
    var post_id = comment.id.substr(2);
    $$("#"+comment.id+" pre[name=code]").each(function(pre, index){
      var location = window.location;
      source_url = location.protocol + "//" + location.host + location.pathname + location.search;
      source_url += "#" + comment.id;
      pre.writeAttribute('codeable_id', post_id);
      pre.writeAttribute('codeable_type', "Post");
      pre.writeAttribute('source_url', source_url);
      pre.writeAttribute('pre_index', index);
      pre.writeAttribute('title', 'java 监控linux CPU 内存 磁盘 JVM：');
    });
  });
  code_favorites_init();

  fix_image_size($$('div.blog_content img'), 700);
  function quote_comment(id) {
    new Ajax.Request('/editor/quote', {
      parameters: {'id':id, 'type':'BlogComment'},
      onSuccess:function(response){editor.bbcode_editor.textarea.insertAfterSelection(response.responseText);
        Element.scrollTo(editor.bbcode_editor.textarea.element);}
    });
  }

  new WeiboShare({share_buttons: $('share_weibo'), img_scope: $('blog_content')});
</script>




        </div>

        <div id="local">
          <div class="local_top"></div>
          <div id="blog_owner">
            <div id="blog_owner_logo"><a href="http://chixianhuadeyu.iteye.com/"><img alt="chixianhuadeyu的博客" class="logo" src="222954_files/a3edb85f-965f-3a8b-8d98-6bbdfe3d39fb.gif" title="chixianhuadeyu的博客: chixianhuadeyu"></a></div>
            <div id="blog_owner_name">chixianhuadeyu</div>
          </div>
          <div id="blog_actions">
            <ul>
              <li>浏览: 28836 次</li>
              <li>性别: <img alt="Icon_minigender_1" src="222954_files/icon_minigender_1.gif" title="男"></li>
              <li>来自: 北京</li>
              <li><img src="222954_files/offline.gif"></li>
              <li>
                <a href="http://chixianhuadeyu.iteye.com/blog/profile" class="profile">详细资料</a>
                <a href="http://chixianhuadeyu.iteye.com/blog/guest_book" class="guest_book">留言簿</a>
              </li>
              
            </ul>
            <h5>搜索本博客</h5>
            <form action="/blog/search" method="get">              <input class="text" id="query" name="query" style="margin-left: 10px; width: 110px;" type="text">
              <input class="submit" value="搜索" type="submit">
            </form>          </div>
          <div id="user_visits" class="clearfix">
            <h5>最近访客 <span style="font-weight:normal;font-size:12px;padding-left:30px;"><a href="http://chixianhuadeyu.iteye.com/blog/user_visits">&gt;&gt;更多访客</a></span></h5>
            
              <div class="user_visit">
                <div class="logo"><a href="http://nosqlfun.iteye.com/" target="_blank"><img alt="上帝的后花园的博客" class="logo" src="222954_files/user-logo-thumb.gif" title="上帝的后花园的博客: 上帝的后花园"></a></div>
                <div class="left"><a href="http://nosqlfun.iteye.com/" target="_blank">上帝的后花园</a></div>
              </div>
            
              <div class="user_visit">
                <div class="logo"><a href="http://eagle123.iteye.com/" target="_blank"><img alt="eagle123的博客" class="logo" src="222954_files/user-logo-thumb.gif" title="eagle123的博客: "></a></div>
                <div class="left"><a href="http://eagle123.iteye.com/" target="_blank">eagle123</a></div>
              </div>
            
              <div class="user_visit">
                <div class="logo"><a href="http://michael9527.iteye.com/" target="_blank"><img alt="michael9527的博客" class="logo" src="222954_files/user-logo-thumb.gif" title="michael9527的博客: "></a></div>
                <div class="left"><a href="http://michael9527.iteye.com/" target="_blank">michael9527</a></div>
              </div>
            
              <div class="user_visit">
                <div class="logo"><a href="http://fxsyp.iteye.com/" target="_blank"><img alt="fxsyp的博客" class="logo" src="222954_files/user-logo-thumb.gif" title="fxsyp的博客: "></a></div>
                <div class="left"><a href="http://fxsyp.iteye.com/" target="_blank">fxsyp</a></div>
              </div>
            
          </div>
                      <div id="blog_menu">
              <h5>博客分类</h5>
              <ul>
                <li><a href="http://chixianhuadeyu.iteye.com/">全部博客 (24)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/26316">ajax (1)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/26631">温暖心灵 (8)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/36219">oracle (4)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/59098">webservice (4)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/62381">appfuse (1)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/71803">windows (1)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/73018">cvsnt (1)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/94711">系统架构师 (1)</a></li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/category/177956">mysql (1)</a></li>
                
              </ul>
            </div>
            
              
              <div id="blog_album">
                <h5>我的相册</h5>
                <div class="picture_thumb" style="float: none">
                  <div><span class="thumb_box"><a href="http://chixianhuadeyu.iteye.com/album"><img src="222954_files/8fa11813-41b8-3b88-b896-5315fc1f4eda-thumb.gif"></a></span></div>
                  <span>ROSA<br> <a href="http://chixianhuadeyu.iteye.com/album">共 2 张</a></span>
                </div>
              </div>
            
            <div id="guest_books">
              <h5>我的留言簿 <span style="font-weight:normal;font-size:12px;padding-left:20px;"><a href="http://chixianhuadeyu.iteye.com/blog/guest_book">&gt;&gt;更多留言</a></span></h5>
              <ul>
                
                  <li>
                  公司问我想要3-5年的规划，我说我要做CTO
<br>
                  -- by <a href="http://chixianhuadeyu.iteye.com/blog/guest_book#16527">cywhoyi</a>
                  </li>
                
                  <li>
                  有没有关于wtc方式方面的原理的东西。<br>
                  -- by <a href="http://chixianhuadeyu.iteye.com/blog/guest_book#4922">zht110227</a>
                  </li>
                
              </ul>
            </div>
            <div id="blog_others">
              <h5>其他分类</h5>
              <ul>
                <li><a href="http://chixianhuadeyu.iteye.com/blog/favorite">我的收藏</a> (6)</li>
                <li><a href="http://chixianhuadeyu.iteye.com/blog/code_favorite">我的代码</a> (0)</li>
                                                <li><a href="http://chixianhuadeyu.iteye.com/blog/topic">我的论坛主题帖</a> (5)</li>
                <li><a href="http://chixianhuadeyu.iteye.com/blog/post">我的所有论坛帖</a> (13)</li>
                <li><a href="http://chixianhuadeyu.iteye.com/blog/article">我的精华良好帖</a> (0)</li>
                              </ul>
            </div>
            <div id="recent_groups">
              <h5>最近加入群组</h5>
              <ul>
                
              </ul>
            </div>
            <div id="month_blogs">
              <h5>存档</h5>
              <ul>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/blog/monthblog/2011-09">2011-09</a> (1)</li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/blog/monthblog/2010-11">2010-11</a> (1)</li>
                
                  <li><a href="http://chixianhuadeyu.iteye.com/blog/monthblog/2010-04">2010-04</a> (1)</li>
                
                <li><a href="http://chixianhuadeyu.iteye.com/blog/monthblog_more">更多存档...</a></li>
              </ul>
            </div>
            
            
            <div id="rss">
              <ul>
                <li><a href="http://chixianhuadeyu.iteye.com/rss" target="_blank"><img alt="Rss" src="222954_files/rss.png"></a></li>
                <li><a href="http://fusion.google.com/add?feedurl=http://chixianhuadeyu.iteye.com/rss" target="_blank"><img alt="Rss_google" src="222954_files/rss_google.gif"></a></li>
              </ul>
            </div>
            <div class="local_bottom"></div>
          
        </div>
      </div>

      <div id="footer" class="clearfix">
        <div id="copyright">
          <hr>
          声明：ITeye文章版权属于作者，受法律保护。没有作者书面许可不得转载。若作者同意转载，必须以超链接形式标明文章原始出处和作者。<br>
          © 2003-2011 ITeye.com.   All rights reserved.  [ 京ICP证110151号  京公网安备110105010620 ]
        </div>
      </div>
    </div>
    <script type="text/javascript">
  document.write("<img src='http://stat.iteye.com/?url="+ encodeURIComponent(document.location.href) + "&referrer=" + encodeURIComponent(document.referrer) + "&user_id=' width='0' height='0' />");
</script><img src="222954_files/a.gif" height="0" width="0">

    
  

</body></html>